const appInst =  getApp();
const utils = require("../../utils/common.js")
const mydebounce = utils.debounce(500) //创建一个防抖函数




/* post提交数据 */
wx.showLoading({title:"加载中..."})
wx.request({
	url: `${app.globalData.server_request_baseUrl}/user_updateContactInfo.php`,
	data: {
		openid: wx.getStorageSync('openid'),
		unionid: wx.getStorageSync('unionid')
	},
	header: {'Content-Type': 'application/x-www-form-urlencoded'},
	method: 'POST',
	dataType: 'json',
	responseType: 'text',
	success: (res) => {
		if (res.data.code == 0) {
			wx.showToast({ title: res.data.msg })
		} else { 
			wx.showToast({ title: res.data.msg })
		}
	},
	fail: () => { wx.showToast({ title: '请求失败' })},
	complete: () => {wx.hideLoading()}
});


wx.showLoading('加载中...')
wx.request({
	url: `${app.globalData.server_request_baseUrl}/user_getUserInfo.php`,
	data: {
		openid : wx.getStorageSync('openid'),
		unionid: wx.getStorageSync('unionid')
	},
	header: { 'content-type': 'application/json' },
	method: 'GET',
	dataType: 'json',
	responseType: 'text',
	success: (res) => {
		console.log(res.data)
		this.setData({
			list : res.data.list
		})
	},
	fail: () => { },
	complete: () => {wx.hideLoading()}
});



//防抖请求
mydebounce(
	() => {
		// 使用promise,这里没有ajax队列就没有意义
		utils.pm({
			url: `${app.globalData.server_request_baseUrl}/user_selectCompany.php`,
			data: {company:event.detail.value},
			method: 'POST'
		}).then(res => { 
			console.log(res.data)
		})
	}
);
//
mydebounce(
	() => {
		utils.request({
			url: `${app.globalData.server_request_baseUrl}/user_selectCompany.php`,
			data: {company:event.detail.value},
			method: 'POST'
		},res => { 
			console.log(res.data)
		})
	}
);